package com.inspectortime.webapp.inspector;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.repository.Repository;
import com.inspectortime.util.SpringValidatorUtils;
import com.mkode.util.java.lang.ClassUtils;

public class PaypalSettingsValidator implements Validator {

	private Repository repository;

	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	public boolean supports(Class clazz) {
		return ClassUtils.isInstanceOf(clazz, InspectorCompany.class);
	}

	public void validate(Object target, Errors errors) {
		InspectorCompany company = (InspectorCompany) target;
		if (StringUtils.isBlank(company.getPaypalPaymentEmail())) {
			errors.reject("inspector.company.missing.paypal.email",
					"Email is required.");
		} else {
			SpringValidatorUtils.rejectInvalidEmail(errors, "paypalPaymentEmail");
		}
	}

}
